package com.zx.crowdfunding.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zx.crowdfunding.entity.Operation;
import com.zx.crowdfunding.entity.OperationExample;
import com.zx.crowdfunding.entity.OperationExample.Criteria;
import com.zx.crowdfunding.mapper.OperationMapper;
import com.zx.crowdfunding.service.api.OperationService;

/**
 * 操作 - Service接口实现类
 * @author 郑雪
 * @date 2021-12-09
 */
@Service
public class OperationServiceImpl implements OperationService {
	
	/**
	 * 操作Mapper接口
	 */
	@Autowired
	private OperationMapper operationMapper;

	@Override
	public List<Operation> getAll() {
		return operationMapper.selectByExample(null);
	}

	@Override
	public void saveOperation(Operation operation) {
		operationMapper.insert(operation);
	}

	@Override
	public void removeOperation(List<Integer> idList) {
		OperationExample example = new OperationExample();
		Criteria criteria = example.createCriteria();
		criteria.andIdIn(idList);
		operationMapper.deleteByExample(example);
	}

	@Override
	public Operation getOperationById(Integer id) {
		return operationMapper.selectByPrimaryKey(id);
	}

	@Override
	public void editOperation(Operation operation) {
		operationMapper.updateByPrimaryKeySelective(operation);
	}

	@Override
	public void saveOperationAuthRelationship(Integer operationId,
			List<Integer> authIdList) {
		// 根据operationId删除旧的关联关系数据
		operationMapper.deleteOperationAuthRelationship(operationId);
		
		// 添加操作与权限的关联关系数据
		if(authIdList != null && authIdList.size()>0){
			operationMapper.insertOperationAuthRelationship(operationId, authIdList);
		}
	}

}
